#include "head.h"

int initTcp(char* ip,char *port){
    int sockfd=socket(AF_INET,SOCK_STREAM,0);

    // int reuse=1;
    // getsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,&reuse,sizeof(reuse));
    
    int flag = 1;
    setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,&flag,sizeof(flag));
    struct sockaddr_in addr;
    addr.sin_addr.s_addr=inet_addr(ip);
    addr.sin_port=htons(atoi(port));
    addr.sin_family=AF_INET;
    int ret= bind(sockfd,(struct sockaddr*)&addr,sizeof(addr));
    ERROR_CHECK(ret,-1,"bind");

    listen(sockfd,50);

    return sockfd;
}